#!/bin/sh

in_file=$1
out_file=$2

if [ -z "$in_file" -o -z "$out_file" ]; then
    echo "USAGE: $0 in_file.spr out_file.png"
    exit 1
fi

[ -d tmp ] && rm -rf tmp
mkdir tmp

./spr2bmp $in_file tmp/img_

num_files=$(ls -1 tmp | wc -l)
if [ "$num_files" != "1" ]; then
    echo "ERROR: image must have only 1 frame (it has $num_files frames)"
    rm -rf tmp
    exit 1
fi

convert tmp/img_000.bmp -transparent '#00ff00' $out_file

rm -rf tmp
